package cn.bdqn.repository;

import cn.bdqn.pojo.Message;
import cn.bdqn.vo.UserMessage;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface Asecu_MessageRepository extends JpaRepository<Message,Integer> {

    @Query("select new cn.bdqn.vo.UserMessage(u,m) from User u,Message m where u.id = m.haveId and m.haveId = :haveId and m.status=1")
    List<UserMessage> findByHaveId(@Param("haveId") Integer haveId);

    @Modifying
    @Query("update Message set beenread = 1 where id = :id")
    void makeAsRead(@Param("id") Integer id);
}
